<template>
  <div class="baobei">
    <el-dialog title="补录领导批示" :visible.sync="leaderApproveVisible" width="80%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <leaderApprove v-bind:personId='personId' :step='selStep' :szData="selectData.szData" @closeDialog="closeAndRefresh"></leaderApprove>
    </el-dialog>
    <el-dialog
      title="批示意见/办理提示"
      :visible.sync="noticeVisible"
      width="60%">
      <notice :timestamp="timestamp" :noticePersonId="noticePersonId" :step="selStep" @refresh="refresh"></notice>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="noticeVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="录入征求意见信息"
      :visible.sync="telRecordVisible"
      width="60%" :close-on-click-modal="false" :close-on-press-escape="false">
        <el-form
          :model="telRecordForm"
          ref="telRecordForm"
          label-width="150px"
          label-position="right"
          :inline="true"
          >
          <div v-if="formFlag===1">
            <el-form-item label="征求意见单位" prop="UnitName">
              <el-input v-model="telRecordForm.UnitName" :rules="[{ required: true, message: '请填写征求意见单位', trigger: 'blur' }]"></el-input>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="征求意见时间" prop="sendTime" :rules="[{ required: true, message: '请填写征求意见时间', trigger: 'blur' }]">
              <el-date-picker
                v-model="telRecordForm.sendTime"
                type="date"
                placeholder="选择日期时间"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="征求意见函文号" prop="sendNum" :rules="[{ required: true, message: '请填写征求意见函文号', trigger: 'blur' }]">
              <el-input v-model="telRecordForm.sendNum"></el-input>
            </el-form-item>
          </div>
          <div style="clear:both" v-if="formFlag===2">
            <el-form-item label="复函时间" prop="receiveTime" :rules="[{ required: true, message: '请填写复函时间', trigger: 'blur' }]">
              <el-date-picker
                v-model="telRecordForm.receiveTime"
                type="date"
                placeholder="选择日期时间"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="复函文号" prop="receiveNum" :rules="[{ required: true, message: '请填写复函文号', trigger: 'blur' }]">
              <el-input v-model="telRecordForm.receiveNum"></el-input>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="反馈结果" prop="receiveContent" :rules="[{ required: true, message: '请填写反馈结果', trigger: 'blur' }]">
              <el-input type="textarea" v-model="telRecordForm.receiveContent" style="width:700px"></el-input>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="上传附件">
                <el-upload
                  class="upload-demo"
                  :action="this.$http.defaults.baseURL+this.$http.defaults.selectionAPI +'api/gen/file/upload/'"
                  :on-success="handleUploadSucc"
                  :on-remove="handleRemove"
                  :before-remove="beforeRemove"
                  :on-error='uploadError'
                  :multiple="true"
                  :file-list="fileList">
                  <el-button type="primary">点击上传</el-button>
                </el-upload>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="telRecordForm.remark" style="width:700px"></el-input>
            </el-form-item>
          </div>
          <el-form-item>
            <el-button type="success" style="margin-left:150px;" @click="finishBL">{{formFlag===1?"保存":"办理完成"}}</el-button>
          </el-form-item>
        </el-form>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection/necessary/manageOpinion' }">征求协管方意见</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <el-tabs v-model="activeName" type="card" @tab-click="tabsClick" style="margin:15px">
            <el-tab-pane label="待办理" name="first">
              <span slot="label" v-if="countnum1>0" class="pointtab"><el-badge :value="countnum1" class="item">待办理</el-badge></span>
                <el-table
                  ref="tableData"
                  v-loading="listloading1"
                  border
                  size="small"
                  :data="tableData"
                  tooltip-effect="dark"
                  style="width: 100%"
                  @selection-change="handleSelectionChange">
                  <el-table-column
                    type="selection"
                    width="55">
                  </el-table-column>
                  <el-table-column
                    label="序号"
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="realName"
                    label="姓名"
                    width="150">
                  </el-table-column>
                  <el-table-column
                    prop="candidateUnit"
                    label="目前单位">
                  </el-table-column>
                  <el-table-column
                    prop="currentJob"
                    label="目前职务"
                    width="250"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="currentLevel"
                    label="目前职级"
                    width="150"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="unitName"
                    label="选任岗位单位"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="jobName"
                    width="250"
                    label="选任岗位职务"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="jobLevel"
                    label="选任岗位职级"
                    width="150"
                    show-overflow-tooltip>
                  </el-table-column>
                </el-table>
                <el-button class="marginT10" type="primary" @click="baobuClick" :loading="submitloading">征求协管方意见</el-button>
              <select-group :backflag="false" :substep="1" :selectData="selectData" :selectPerson="baobeiPersons" :selApi="selApi" :selStep="selStep" @getList="getList"></select-group>
            </el-tab-pane>
            <el-tab-pane label="办理中" name="second">
              <span slot="label" v-if="countnum2>0" class="pointtab"><el-badge :value="countnum2" class="item">办理中</el-badge></span>
              <el-table
                v-loading="listloading2"
                border
                size="small"
                ref="multipleTable"
                :data="tableData2"
                tooltip-effect="dark"
                style="width: 100%">
                <el-table-column
                  label="序号"
                  type="index"
                  width="50">
                </el-table-column>
                <el-table-column
                  prop="names"
                  label="人选"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="580">
                  <template slot-scope="scope">
                    <!-- <el-button type="primary" size="small" class="marginL8" @click="uploadFJ(scope.row)">上传附件</el-button> -->
                    <el-button @click="telRecord(scope.row,1)" type="success">录入征求意见信息</el-button>
                    <el-button @click="exportZqyjh(scope.row.id)" type="primary">导出征求意见函</el-button>
                    <el-button @click="telRecord(scope.row,2)" type="success">录入复函信息</el-button>
                    <el-button @click="delBL(scope.row)" type="danger" class="marginL8">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="待批示" name="third">
              <span slot="label" v-if="countnum3>0" class="pointtab"><el-badge :value="countnum3" class="item">待批示</el-badge></span>
              <el-table
                v-loading="listloading3"
                border
                size="small"
                :data="tableData3"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange3">
                <el-table-column
                  type="selection"
                  width="45">
                </el-table-column>
                <el-table-column
                  label="序号"
                  type="index"
                  width="55">
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="candidateUnit"
                  label="目前单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="currentJob"
                  label="目前职务"
                  width="150"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="currentLevel"
                  label="目前职级"
                  width="120"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="选任岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobName"
                  width="150"
                  label="选任岗位职务"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="选任岗位职级"
                  width="120"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="stepManageOpinionUsername"
                  label="办理人">
                </el-table-column>
                <el-table-column
                  label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button @click="detailShow(scope.row,3)" type="primary">查看</el-button>
                    <el-button @click="addLeaderApprove(scope.row.personId)">补录领导批示</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="是否同意" width="170">
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.passed" @change="changeThisRadio">
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                  </template>
                </el-table-column>
              </el-table>
              <select-group :backflag="false" :substep="3" :selectData="selectData" :selectPerson="selectPerson" :selApi="selApi" :selStep="selStep" @getList="getList3"></select-group>
            </el-tab-pane>
            <el-tab-pane label="已批示" name="fourth">
              <span slot="label" v-if="countnum4>0" class="pointtab"><el-badge :value="countnum4" class="item">已批示</el-badge></span>
              <el-table
                v-loading="listloading4"
                border
                size="small"
                :data="tableData4"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange4">
                <el-table-column
                  type="selection"
                  width="55">
                </el-table-column>
                <el-table-column
                  label="序号"
                  type="index"
                  width="50">
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="90"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="选任岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobName"
                  width="150"
                  label="选任岗位职务"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="选任岗位职级"
                  width="110"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="250">
                  <template slot-scope="scope">
                    <el-button @click="detailShow(scope.row,4)" type="primary">查看</el-button>
                    <el-button @click="addLeaderApprove(scope.row.personId)">补录领导批示</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="是否同意" width="150">
                  <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.passed" @change="changeThisRadio">
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                  </template>
                </el-table-column>
                <el-table-column
                  label="办理提示、批示意见" width="170">
                  <template slot-scope="scope">
                    <el-popover placement="bottom" width="600" trigger="hover">
                      <notice :timestamp="timestamp" :noticePersonId="scope.row.personId" :step="selStep" @refresh="refresh"></notice>
                      <el-button size="small" slot="reference" type="primary" @click="showNotice(scope.row.personId)">查看详情</el-button>
                    </el-popover>
                  </template>
                </el-table-column>
              </el-table>
              <el-button type="success" @click="saveComplete" style="margin:15px 0" :loading="submitloading2">征求协管方意见完成</el-button>
              <div style="border-top:1px solid #74A6CC;margin-bottom:15px"></div>
              <select-group :backflag="false" :substep="4" :selectData="selectData" :selectPerson="selectPerson2" :selApi="selApi" :selStep="selStep" @getList="getList4"></select-group>
            </el-tab-pane>
          </el-tabs>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import selectGroup from '../common/SelectGroup2'
import notice from '../common/Notice'
import leaderOpinion from '../common/leaderOpinion'
import leaderApprove from '../common/leaderApprove'
export default {
  name: 'manageOpinion',
  components: {
    selectGroup,
    notice,
    leaderOpinion,
    leaderApprove
  },
  data () {
    return {
      formFlag: 1,
      timestamp: '',
      personId: '',
      leaderApproveVisible: false,
      leaderMsg: {},
      telRecordForm: {
        UnitName: '',
        sendTime: '',
        sendNum: '',
        receiveTime: '',
        receiveNum: '',
        receiveContent: '',
        remark: ''
      },
      manageOpinionBatchId: '',
      telRecordVisible: false,
      countnum1: 0,
      countnum2: 0,
      countnum3: 0,
      countnum4: 0,
      tableHeight: 100,
      activeName: 'first',
      listloading1: false,
      listloading2: false,
      listloading3: false,
      listloading4: false,
      submitloading: false,
      submitloading2: false,
      tableData: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      baobeiPersons: [], // 代办理表格 table select change
      files: [],
      fileList: [], // 办理中 上传附件
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      },
      selectPerson: [], // 待批示
      selectPerson2: [], // 已批示
      selApi: 'api/selection/manageOpinion/submitApprove',
      selStep: 13,
      noticePersonId: '', // notice persion id
      noticeVisible: false // 已批示
    }
  },
  methods: {
    changeThisRadio (val) {
      if (val === 0) {
        this.$message({
          message: '此操作将终止改人选选任工作',
          type: 'warning'
        })
      }
    },
    exportZqyjh (id) {
      let url = this.$http.defaults.selectionAPI + 'api/selection/document/exportZqyjh?batchId=' + id
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.download(res.data.result)
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    detailShow (item, backstep) {
      console.log(item)
      item.backStep = backstep
      this.$router.push({
        name: 'manageOpinionDetailShow',
        params: item
      })
    },
    refresh () {
      this.getList3()
      this.getList4()
      this.timestamp = new Date().getTime()
    },
    closeAndRefresh () {
      this.leaderApproveVisible = false
      this.getList3()
      this.getList4()
      this.timestamp = new Date().getTime()
    },
    addLeaderApprove (id) {
      this.leaderApproveVisible = true
      this.personId = id
    },
    showNotice (id) {
      console.log('show notice id:', id)
      this.noticePersonId = id
      this.noticeVisible = true
      this.timestamp = new Date().getTime()
    },
    // 导出接口
    exportTelRecord (id) {
      let url = this.$http.defaults.selectionAPI + 'api/selection/document/exportDhjlb?batchId=' + id
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.download(res.data.result)
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      // window.open(this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/selection/document/exportDhjlb?batchId=' + id)
    },
    download (fileid) {
      var downloadElement = document.createElement('a')
      downloadElement.href = this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/download?id=' + fileid
      document.body.appendChild(downloadElement)
      downloadElement.click() // 点击下载
      document.body.removeChild(downloadElement) // 下载完成移除元素
    },
    telRecord (data, flag) {
      this.formFlag = flag
      this.manageOpinionBatchId = data.id
      this.telRecordVisible = true
      if (this.$refs['telRecordForm']) {
        this.$refs['telRecordForm'].resetFields()
      }
      if (data.sendRecord) {
        this.telRecordForm.UnitName = JSON.parse(data.sendRecord).UnitName
        this.telRecordForm.sendTime = JSON.parse(data.sendRecord).sendTime
        this.telRecordForm.sendNum = JSON.parse(data.sendRecord).sendNum
      } else {
        this.telRecordForm.UnitName = ''
        this.telRecordForm.sendTime = ''
        this.telRecordForm.sendNum = ''
      }
      if (data.receiveRecord) {
        this.telRecordForm.receiveTime = JSON.parse(data.receiveRecord).receiveTime
        this.telRecordForm.receiveNum = JSON.parse(data.receiveRecord).receiveNum
        this.telRecordForm.receiveContent = JSON.parse(data.receiveRecord).receiveContent
      } else {
        this.telRecordForm.receiveTime = ''
        this.telRecordForm.receiveNum = ''
        this.telRecordForm.receiveContent = ''
      }
      this.telRecordForm.remark = data.remark
      // console.log('fileList网络获取')
      this.fileList = []
      if (data.files) {
        for (let item of data.files) {
          console.log({id: item.id, url: item.relativePath, name: item.fileName + '.' + item.fileType})
          this.fileList.push({id: item.id, url: item.relativePath, name: item.fileName + '.' + item.fileType})
        }
      }
    },
    getNum () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/statnum/manageOpinion/getStatNum'
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.countnum1 = res.data.result.countnum1
          this.countnum2 = res.data.result.countnum2
          this.countnum3 = res.data.result.countnum3
          this.countnum4 = res.data.result.countnum4
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    saveComplete () {
      if (this.selectPerson2.length === 0) {
        this.$message({
          message: '请至少选择一个人选',
          type: 'error'
        })
        return
      }
      let url = this.$http.defaults.selectionAPI + this.selApi
      let arr = []
      for (let i of this.selectPerson2) {
        if (i.passed !== 1 && i.passed !== 0) {
          this.$message({
            message: '请选择每一位勾选人选是否同意',
            type: 'warning'
          })
          return
        } else {
          arr.push({
            id: i.personId,
            passed: i.passed
          })
        }
      }
      this.submitloading2 = true
      this.$http.post(url, {
        receiveUserId: -1,
        persons: arr,
        step: 13
      }).then(res => {
        this.submitloading2 = false
        if (res.data.success === true) {
          this.$message({
            message: '办理完成',
            type: 'success'
          })
          this.getList4()
        }
      })
    },
    loadSelectData1 () {
      this.selectData = {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=3`)
        .then(response => {
          if (response.data.success) {
            this.selectData.cnData = []
            for (let i = 0; i < response.data.result.length; i++) {
              this.selectData.cnData.push(response.data.result[i])
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=13`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    loadSelectData () {
      this.selectData = {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=2`)
        .then(response => {
          if (response.data.success) {
            this.selectData.szData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].roleName === 'ROLE_sizhang' || response.data.result[i].manageDep.indexOf(localStorage.getItem('unitName')) > -1) {
                this.selectData.szData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=13`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    tabsClick (tab) {
      // console.log(tab)
      if (tab.name === 'first') {
        console.log('first in')
        this.getList()
      } else if (tab.name === 'second') {
        this.getList2()
      } else if (tab.name === 'third') {
        this.getList3()
      } else if (tab.name === 'fourth') {
        this.getList4()
      }
    },
    getList () {
      this.getNum()
      this.listloading1 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/getNotProcessedPersons?sended=0'
      // console.log(url)
      this.$http.get(url).then(res => {
        this.listloading1 = false
        console.log('get list succ:', res)
        if (res.data.success === true) {
          this.tableData = res.data.result
          this.$nextTick(() => {
            this.tableData.forEach(row => {
              if (row.personId === this.$route.params.selectPersonId) {
                this.$refs.tableData.toggleRowSelection(row)
                this.$route.params.selectPersonId = null
              }
            })
          })
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData1()
    },
    getList2 () {
      this.getNum()
      this.listloading2 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/getProcessingBatchInfo'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        this.listloading2 = false
        console.log('get list22 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          let arr = []
          for (let i of rs) {
            let brr = []
            for (let j of i.persons) {
              brr.push(j.realName)
            }
            arr.push({
              id: i.id,
              names: brr.join(' '),
              files: i.files,
              persons: i.persons,
              sendRecord: i.sendRecord,
              receiveRecord: i.receiveRecord,
              remark: i.remark
            })
          }
          this.tableData2 = arr
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    getList3 () {
      this.getNum()
      this.listloading3 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/getCompletedNoApprovePersons'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        this.listloading3 = false
        console.log('get list33 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          let arr = []
          for (let i of rs) {
            arr.push({
              candidateUnit: i.candidateUnit,
              currentJob: i.currentJob,
              currentLevel: i.currentLevel,
              jobLevel: i.jobLevel,
              jobName: i.jobName,
              personId: i.personId,
              manageOpinionBatchId: i.manageOpinionBatchId,
              realName: i.realName,
              unitName: i.unitName,
              stepManageOpinionUsername: i.stepManageOpinionUsername,
              files: i.files
            })
          }
          this.tableData3 = arr
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData()
    },
    getList4 () {
      this.getNum()
      this.listloading4 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/getApprove'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        this.listloading4 = false
        console.log('get list44 succ:', res)
        if (res.data.success === true) {
          this.tableData4 = res.data.result
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData()
    },
    handleSelectionChange (val) { // 报部 待办理
      console.log('tabledata val:', val)
      this.baobeiPersons = [...val]
    },
    baobuClick () { // 报中组部 按钮
      this.submitloading = true
      console.log('click baobu')
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/saveBatchByPersons'
      // console.log(url)
      // 获取报备persons
      let arr = []
      for (let i of this.baobeiPersons) {
        arr.push(i.personId)
      }
      this.$http.post(url, {
        personIds: arr
      }).then(res => {
        this.submitloading = false
        console.log(' succ res:', res)
        if (res.data.success === true) {
          this.$message({
            message: '提交成功',
            type: 'success'
          })
          this.getList()
        }
      })
    },
    handleSelectionChange2 (val) { // 报部 办理中
      console.log('tabledata2 val:', val)
    },
    handleUploadSucc (response, file, fileList) { // 带上会审议 录入领导批示 附件
      console.log(response)
      if (response.success) {
        this.files.push(response.result[0])
        this.$message({
          message: '上传成功！' + response.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    beforeRemove (file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleRemove (file, fileList) {
      console.log(file, fileList)
      let fid = file.id
      let url = this.$http.defaults.selectionAPI + 'api/gen/file/remove'
      this.$http.get(url, {
        params: {
          id: fid
        }
      }).then(res => {
        console.log('删除成功:', res)
        if (res.data.success === true) {
          let index = this.files.indexOf(fid)
          if (index !== -1) {
            this.files.splice(index, 1)
            this.$message({
              message: '删除成功！',
              type: 'success'
            })
          }
          this.getList2()
        }
      })
    },
    uploadError (err) {
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    finishBL () { // 办理中 完成
      this.$refs['telRecordForm'].validate((valid) => {
        if (valid) {
          let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/updateManageOpinionBatch'
          let sendRecord = {UnitName: this.telRecordForm.UnitName, sendTime: this.telRecordForm.sendTime, sendNum: this.telRecordForm.sendNum}
          let receiveRecord = {receiveTime: this.telRecordForm.receiveTime, receiveNum: this.telRecordForm.receiveNum, receiveContent: this.telRecordForm.receiveContent}
          let arr = []
          for (let i of this.files) {
            arr.push(i.id)
          }
          let para = {
            manageOpinionBatchId: this.manageOpinionBatchId,
            sendRecord: JSON.stringify(sendRecord)
          }
          if (this.formFlag === 2) {
            para = {
              manageOpinionBatchId: this.manageOpinionBatchId,
              receiveRecord: JSON.stringify(receiveRecord),
              remark: this.telRecordForm.remark,
              files: arr
            }
          }
          this.$http.post(url, para).then(res => {
            if (res.data.success === true) {
              if (this.formFlag === 2) {
                this.stepCompleted(this.manageOpinionBatchId)
              } else {
                this.$message({
                  message: '保存成功',
                  type: 'success'
                })
                this.telRecordVisible = false
                this.getList2()
              }
            }
          })
        }
      })
    },

    stepCompleted () { // 办理中 完成
      let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/updateManageOpinionState'
      this.$http.post(url, {
        manageOpinionBatchId: this.manageOpinionBatchId
      }).then(res => {
        if (res.data.success === true) {
          this.$message({
            message: '已完成',
            type: 'success'
          })
          this.telRecordVisible = false
        } else {
          this.$message({
            message: '更新失败：' + res.data.message,
            type: 'error'
          })
        }
        this.getList2()
      })
    },
    delBL (item) { // 办理中 删除
      console.log('del', item)
      this.$confirm('是否删除待上会审议批次', '操作确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = this.$http.defaults.selectionAPI + 'api/selection/manageOpinion/removeBatch'
        this.$http.get(url, {
          params: {
            manageOpinionBatchId: item.id
          }
        }).then(res => {
          console.log('删除办理批次res:', res)
          if (res.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getList2()
          }
        })
      }).catch(() => {
        console.log('取消删除')
      })
    },
    handleSelectionChange3 (val) { // 待批示
      console.log('tabledata3 val:', val)
      this.selectPerson = [...val]
    },
    handleSelectionChange4 (val) { // 已批示
      console.log('tabledata4 val:', val)
      this.selectPerson2 = [...val]
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    let params = this.$route.params
    if (params && params.step) {
      console.log('in params')
      if (params.step === 1) {
        this.activeName = 'first'
        this.getList()
      }
      if (params.step === 2) {
        this.activeName = 'second'
        this.getList2()
      }
      if (params.step === 3) {
        this.activeName = 'third'
        this.getList3()
      }
      if (params.step === 4) {
        this.activeName = 'fourth'
        this.getList4()
      }
    } else {
      this.getList()
    }
    // let params = this.$route.params
    // console.log('讨论决定详情params:', params)
    // 代办理列表
    // resize
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>

<style>
.baobei .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.baobei .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.baobei .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.baobei .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.baobei .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.baobei .el-table__row{
  height: 50px;
}
</style>
<style scoped>
.baobei {
  width: 100%;
}
.baobei .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
